home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / REMLIFE.ARJ / REMTAB.PAS < prev   
Pascal/Delphi Source File  |  1989-10-24  |  3KB  |  131 lines

  1. {$B+}    {Boolean complete evaluation on}
  2.  
  3. PROGRAM REMTAB;
  4.  
  5. { Removes tabs from a file and replaces then with 5 blanks }
  6.  
  7.  
  8. Uses
  9.   Crt, {Unit found in TURBO.TPL}
  10.   Dos;
  11.  
  12. TYPE
  13.   FILETYPE = TEXT;
  14.   FILENAME = STRING[255]; { full path name }
  15.  
  16.  
  17. VAR
  18.   INFILE, BACKUP, OUTFILE : FILETYPE;
  19.   INNAME, BACKNAME, OUTNAME : FILENAME;
  20.   BFILEVAR : FILE;
  21.  
  22. Procedure Init;
  23.  
  24. Procedure MakeBackup;
  25.  VAR
  26.    I,J : INTEGER;
  27.    Ch  : Char;
  28.    DirInfo : SearchRec;
  29.   BEGIN
  30.     BackName := InName;
  31.     I := 1;
  32.     J := length(InName);
  33.     While (I <> J) AND (BackName[I] <> '.') do
  34.       I := succ(I);
  35.     I := Succ(I);
  36.     BackName[I] := 'B'; BackName[I+1] := 'A'; BackName[I+2] := 'K';
  37.     If I > J
  38.       THEN BackName[0] := CHR(J + 3)
  39.       ELSE BackName[0] := CHR(J-(J-I+1) + 3);
  40.     WriteLn;
  41.     FindFirst(InName,AnyFile,DirInfo); { Look At this }
  42.     If DosError <> 0 { Then -- oops, input file non existent }
  43.       Then
  44.         begin
  45.           Write('Input file does not exist...exiting.');
  46.           Halt(1);
  47.         end;
  48.     Write('Backing Up File....');
  49.     Assign(BfileVar,BackName); { Do this to....}
  50.     FindFirst(BackName,AnyFile,DirInfo); { Check Existence of backup }
  51.     If DosError = 0 { Then the file was found -- Delete the old backup }
  52.       Then Erase(BfileVar);
  53.     Assign(BfileVar,InName);    { assign }
  54.     Rename(BFILEVAR,BackName);
  55.     WriteLn('DONE.');
  56.   END;
  57.  
  58. BEGIN
  59.   WriteLn('REMTAB -- Removes Tab Characters from Printable file');
  60.   If (ParamCount = 0)
  61.     Then
  62.       begin
  63.         Write('Pathname of file :: ');
  64.         ReadLn(InName); { Get the file name }
  65.       end
  66.     else
  67.       begin
  68.         InName := ParamStr(1);
  69.         WriteLn(InName,' is the file to process.');
  70.       end;
  71.   If InName = ''
  72.     Then
  73.       begin
  74.            WriteLn('No File Name Specified... Exiting.');
  75.            Halt(1);
  76.       end;
  77.   MakeBackUp;
  78. END;
  79.  
  80. PROCEDURE RUN;
  81. VAR
  82.   CH : Char;
  83.   Place : Integer;
  84. BEGIN
  85.   Place := 1;
  86.   OutName := InName;
  87.   InName := BackName;
  88.   Assign (Infile,InName);
  89.   Reset(InFile);
  90.   Assign (Outfile,OutName);
  91.   ReWrite(OutFile);
  92.   Write('Converting......');
  93.   While NOT Eof(InFile) DO
  94.     BEGIN
  95.       Read(Infile,CH); { Get a Char }
  96.       If CH = Chr(9) { Tab? }
  97.          Then Begin
  98.                 IF ((Place MOD 8) = 0) THEN
  99.                   Begin
  100.                     Write(OutFile,' ');
  101.                     Place := Succ(Place);
  102.                   End;
  103.                 IF ((Place MOD 8) <> 0) THEN
  104.                    Repeat
  105.                      Write(OutFile,' ');
  106.                      Place := Succ(Place);
  107.                    Until ((Place MOD 8) = 0);
  108.                End
  109.          Else If Ch = Chr(13)
  110.                  Then Begin
  111.                         Place := -1;
  112.                         Write(OutFile,Ch);
  113.                       End
  114.                  Else Begin
  115.                         Write(OutFile,Ch);
  116.                         Place := Succ(Place);
  117.                       End;
  118.     End;
  119.   Close(InFile);
  120.   Close(OutFile);
  121.   WriteLn('DONE!');
  122. END;
  123.  
  124.  
  125.  
  126. BEGIN { MAIN }
  127.   TextColor(LightGray);
  128.   Init;
  129.   Run;
  130. END.
  131.